<?php


namespace App\Services\Repositories\Admin;

use App\Models\Admin\PanxAdmin;
use App\Services\Repositories\Connector\AdminInterface;
use App\Services\Utils\ApiChecker;
use Tymon\JWTAuth\Contracts\JWTSubject;


class PanxAdminRepository implements AdminInterface
{
    use ApiChecker;

    /**
     * @param string $account
     * @return PanxAdmin
     * @throws \Exception
     */
    public function findAdmin(string $account): PanxAdmin
    {
        /** @var PanxAdmin $admin */
        $admin = (new PanxAdmin)
            ->where('account', $account)
            ->first();

        $this->checkIsTrue($admin, trans('middleware.account_not_found'));
        $this->checkUnless($admin->is_deleted, trans('middleware.account_disabled'));

        return $admin;
    }

    /**
     * @param JWTSubject $admin
     * @return PanxAdmin|JWTSubject
     */
    public function loginAdminInfo(JWTSubject $admin)
    {
        $admin->provider_type = null;
        $admin->has_hair = null;
        $admin->store_id = null;
        $admin->customer_id = null;

        return $admin;
    }
}